from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-24 14:28:57.220956
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 24, Jan, 2021
Time: 14:29:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.4490
Nobs: 181.000 HQIC: -46.3946
Log likelihood: 2035.61 FPE: 3.72823e-21
AIC: -47.0394 Det(Omega_mle): 2.29778e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.445008 0.143964 3.091 0.002
L1.Burgenland 0.125916 0.075617 1.665 0.096
L1.Kärnten -0.233423 0.061602 -3.789 0.000
L1.Niederösterreich 0.124209 0.173943 0.714 0.475
L1.Oberösterreich 0.225093 0.149958 1.501 0.133
L1.Salzburg 0.186152 0.079660 2.337 0.019
L1.Steiermark 0.099585 0.107792 0.924 0.356
L1.Tirol 0.156358 0.072195 2.166 0.030
L1.Vorarlberg -0.005320 0.067223 -0.079 0.937
L1.Wien -0.109153 0.144592 -0.755 0.450
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.504375 0.182982 2.756 0.006
L1.Burgenland 0.017469 0.096111 0.182 0.856
L1.Kärnten 0.370839 0.078298 4.736 0.000
L1.Niederösterreich 0.107245 0.221085 0.485 0.628
L1.Oberösterreich -0.165003 0.190600 -0.866 0.387
L1.Salzburg 0.185085 0.101250 1.828 0.068
L1.Steiermark 0.249631 0.137006 1.822 0.068
L1.Tirol 0.139548 0.091762 1.521 0.128
L1.Vorarlberg 0.178386 0.085442 2.088 0.037
L1.Wien -0.575020 0.183780 -3.129 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.302582 0.064454 4.695 0.000
L1.Burgenland 0.113602 0.033854 3.356 0.001
L1.Kärnten -0.025400 0.027580 -0.921 0.357
L1.Niederösterreich 0.052421 0.077875 0.673 0.501
L1.Oberösterreich 0.284838 0.067137 4.243 0.000
L1.Salzburg 0.004509 0.035664 0.126 0.899
L1.Steiermark -0.020846 0.048259 -0.432 0.666
L1.Tirol 0.094836 0.032322 2.934 0.003
L1.Vorarlberg 0.115620 0.030096 3.842 0.000
L1.Wien 0.083470 0.064734 1.289 0.197
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210569 0.074770 2.816 0.005
L1.Burgenland -0.006489 0.039273 -0.165 0.869
L1.Kärnten 0.023646 0.031994 0.739 0.460
L1.Niederösterreich 0.030243 0.090340 0.335 0.738
L1.Oberösterreich 0.387972 0.077883 4.981 0.000
L1.Salzburg 0.095321 0.041373 2.304 0.021
L1.Steiermark 0.184178 0.055984 3.290 0.001
L1.Tirol 0.044585 0.037496 1.189 0.234
L1.Vorarlberg 0.092165 0.034913 2.640 0.008
L1.Wien -0.064665 0.075096 -0.861 0.389
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.546135 0.148428 3.679 0.000
L1.Burgenland 0.076972 0.077962 0.987 0.323
L1.Kärnten 0.005546 0.063512 0.087 0.930
L1.Niederösterreich -0.028051 0.179336 -0.156 0.876
L1.Oberösterreich 0.133490 0.154607 0.863 0.388
L1.Salzburg 0.050643 0.082130 0.617 0.537
L1.Steiermark 0.121386 0.111135 1.092 0.275
L1.Tirol 0.221863 0.074434 2.981 0.003
L1.Vorarlberg 0.014040 0.069307 0.203 0.839
L1.Wien -0.128600 0.149075 -0.863 0.388
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157764 0.105750 1.492 0.136
L1.Burgenland -0.020451 0.055545 -0.368 0.713
L1.Kärnten -0.013337 0.045250 -0.295 0.768
L1.Niederösterreich 0.139859 0.127771 1.095 0.274
L1.Oberösterreich 0.384926 0.110152 3.494 0.000
L1.Salzburg -0.026172 0.058515 -0.447 0.655
L1.Steiermark -0.035754 0.079179 -0.452 0.652
L1.Tirol 0.189289 0.053032 3.569 0.000
L1.Vorarlberg 0.048916 0.049379 0.991 0.322
L1.Wien 0.181991 0.106211 1.713 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.229072 0.134390 1.705 0.088
L1.Burgenland 0.081872 0.070588 1.160 0.246
L1.Kärnten -0.053185 0.057505 -0.925 0.355
L1.Niederösterreich -0.046490 0.162374 -0.286 0.775
L1.Oberösterreich -0.088953 0.139985 -0.635 0.525
L1.Salzburg 0.030688 0.074362 0.413 0.680
L1.Steiermark 0.365184 0.100623 3.629 0.000
L1.Tirol 0.506828 0.067394 7.520 0.000
L1.Vorarlberg 0.180867 0.062752 2.882 0.004
L1.Wien -0.204341 0.134976 -1.514 0.130
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131216 0.159695 0.822 0.411
L1.Burgenland 0.016536 0.083880 0.197 0.844
L1.Kärnten -0.108308 0.068334 -1.585 0.113
L1.Niederösterreich 0.224769 0.192949 1.165 0.244
L1.Oberösterreich 0.024167 0.166343 0.145 0.884
L1.Salzburg 0.217789 0.088365 2.465 0.014
L1.Steiermark 0.120698 0.119571 1.009 0.313
L1.Tirol 0.097302 0.080084 1.215 0.224
L1.Vorarlberg 0.023043 0.074568 0.309 0.757
L1.Wien 0.264070 0.160391 1.646 0.100
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.582127 0.085662 6.796 0.000
L1.Burgenland -0.022508 0.044994 -0.500 0.617
L1.Kärnten -0.002002 0.036655 -0.055 0.956
L1.Niederösterreich -0.036971 0.103500 -0.357 0.721
L1.Oberösterreich 0.286403 0.089228 3.210 0.001
L1.Salzburg 0.016261 0.047400 0.343 0.732
L1.Steiermark 0.012537 0.064139 0.195 0.845
L1.Tirol 0.074816 0.042958 1.742 0.082
L1.Vorarlberg 0.153795 0.039999 3.845 0.000
L1.Wien -0.060463 0.086035 -0.703 0.482
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.151430 0.000840 0.218047 0.255003 0.066389 0.081261 -0.066907 0.165674
Kärnten 0.151430 1.000000 0.019604 0.198363 0.161508 -0.113580 0.170880 0.024613 0.315884
Niederösterreich 0.000840 0.019604 1.000000 0.296778 0.083706 0.223639 0.131540 0.055187 0.362577
Oberösterreich 0.218047 0.198363 0.296778 1.000000 0.294152 0.311136 0.097018 0.080426 0.131565
Salzburg 0.255003 0.161508 0.083706 0.294152 1.000000 0.161275 0.073468 0.073760 -0.013795
Steiermark 0.066389 -0.113580 0.223639 0.311136 0.161275 1.000000 0.110380 0.089670 -0.097263
Tirol 0.081261 0.170880 0.131540 0.097018 0.073468 0.110380 1.000000 0.157557 0.140501
Vorarlberg -0.066907 0.024613 0.055187 0.080426 0.073760 0.089670 0.157557 1.000000 0.077360
Wien 0.165674 0.315884 0.362577 0.131565 -0.013795 -0.097263 0.140501 0.077360 1.000000